﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;

namespace NotebookS2
{
    public partial class ReportLayoutManager : RibbonForm
    {
        public ReportLayoutManager()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        public DataTable LineItems { get; set; }

        private void ReportLayoutManager_Load(object sender, EventArgs e)
        {
            ObjectTypeManager oManager = new ObjectTypeManager();
            DataTable dt = new DataTable();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            dt = oManager.GetObjectTypes();
            oManager.Close();

            this.LineItems = dt;

            gridControl1.DataSource = this.LineItems;
            gridControl1.Refresh();

            gridView1.ExpandAllGroups();


        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to update changes?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                ObjectTypeManager oManager = new ObjectTypeManager();

                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();
                oManager.UpdateReportLayout(this.LineItems);
                oManager.Close();

                MessageBox.Show("Layout is successfully updated!!!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void txtFileName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            openFileDialog1.FileName = "";
            
            DialogResult result = openFileDialog1.ShowDialog();
            
            if (result == System.Windows.Forms.DialogResult.OK)
            {
              
                string file = openFileDialog1.FileName;

                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["PrintLayout1"], file);

            }

        }

        private void txtDraftLayoutFile_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            openFileDialog1.FileName = "";
          
            DialogResult result = openFileDialog1.ShowDialog();
         
            if (result == System.Windows.Forms.DialogResult.OK)
            {
               
                string file = openFileDialog1.FileName;

                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["PrintLayout2"], file);

            }
        }

        private void txtPrintedLayoutFile_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            openFileDialog1.FileName = "";
            
            DialogResult result = openFileDialog1.ShowDialog();
            
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                string file = openFileDialog1.FileName;


                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["PrintLayout3"], file);

            }
        }
    }
}
